# -*- coding: utf-8 -*-
#--------------------------------------------------------------------------
# Copyright (c) 2009 Barry Schwartz
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

#--------------------------------------------------------------------------
#
# Cython interface to ImageMagick
#

cdef extern from *:

    ctypedef enum MagickBooleanType:
        MagickFalse = 0
        MagickTrue = 1

    ctypedef enum ChannelType:
        UndefinedChannel
        RedChannel = 0x0001
        GrayChannel = 0x0001
        CyanChannel = 0x0001
        GreenChannel = 0x0002
        MagentaChannel = 0x0002
        BlueChannel = 0x0004
        YellowChannel = 0x0004
        AlphaChannel = 0x0008
        OpacityChannel = 0x0008
        MatteChannel = 0x0008   # deprecated
        BlackChannel = 0x0020
        IndexChannel = 0x0020
        AllChannels = 0x002F
        # special channel types
        TrueAlphaChannel = 0x0040 # extract actual alpha channel from opacity
        RGBChannels = 0x0080   # set alpha from  grayscale mask in RGB
        GrayChannels = 0x0080
        SyncChannels = 0x0100   # channels should be modified equally
        DefaultChannels = 0x0127 # ((AllChannels | SyncChannels) & ~OpacityChannel)

    ctypedef enum ImageType:
        UndefinedType
        BilevelType
        GrayscaleType
        GrayscaleMatteType
        PaletteType
        PaletteMatteType
        TrueColorType
        TrueColorMatteType
        ColorSeparationType
        ColorSeparationMatteType
        OptimizeType
        PaletteBilevelMatteType

    ctypedef enum ColorspaceType:
        UndefinedColorspace
        RGBColorspace
        GRAYColorspace
        TransparentColorspace
        OHTAColorspace
        LabColorspace
        XYZColorspace
        YCbCrColorspace
        YCCColorspace
        YIQColorspace
        YPbPrColorspace
        YUVColorspace
        CMYKColorspace
        sRGBColorspace
        HSBColorspace
        HSLColorspace
        HWBColorspace
        Rec601LumaColorspace
        Rec601YCbCrColorspace
        Rec709LumaColorspace
        Rec709YCbCrColorspace
        LogColorspace
        CMYColorspace

    ctypedef enum StorageType:
        UndefinedPixel
        CharPixel
        DoublePixel
        FloatPixel
        IntegerPixel
        LongPixel
        QuantumPixel
        ShortPixel

cdef extern from "wand/magick_wand.h":

    cdef struct _MagickWand:
        pass
    ctypedef _MagickWand MagickWand

    void MagickWandGenesis()
    void MagickWandTerminus()
    MagickWand *NewMagickWand()
    void DestroyMagickWand(MagickWand *wand)
    MagickBooleanType MagickReadImage(MagickWand *wand, char *filename)
    MagickBooleanType MagickPingImage(MagickWand *wand, char *filename)
    unsigned long MagickGetImageWidth(MagickWand *wand)
    unsigned long MagickGetImageHeight(MagickWand *wand)
    char *MagickGetImageFormat(MagickWand *wand)
    MagickBooleanType MagickDisplayImage(MagickWand *wand, char *server_name)
    unsigned long MagickGetImageChannelDepth(MagickWand *wand, ChannelType channel)
    ColorspaceType MagickGetImageColorspace(MagickWand *wand)
    ImageType MagickGetImageType(MagickWand *wand)
    MagickBooleanType MagickSetImageType(MagickWand *wand, ImageType image_type)
    unsigned long MagickGetImageAlphaChannel(MagickWand *wand)
    MagickBooleanType MagickExportImagePixels(MagickWand *wand,
                                              long x_offset, long y_offset,
                                              unsigned long columns, unsigned long rows,
                                              char *map, StorageType storage,
                                              unsigned char *pixels)

cpdef apply_tiff_predictor_2(unsigned int width, unsigned int height,
                             order, storage, unsigned char *pixels)
